﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Web.Mvc;
namespace JULONG.WEB.Library.expViewResult
{
    //返回V层的json格式
    public class myJson
    {
        static JsonResult JsonResult = new JsonResult() { JsonRequestBehavior = JsonRequestBehavior.AllowGet };
        static Dictionary<string, object> data = new Dictionary<string, object>();

        public static JsonResult success(object content = null, resultActionEnum action = resultActionEnum.none, string jsonType = "applaction/json")
        {
            if (content == null) content = "成功";
            data["result"] = resultTypeEnum.SUCCESS.ToString();
            data["content"] = content;
            data["action"] = action.ToString();
            JsonResult.Data = data;
            if (jsonType != null)
            {
                JsonResult.ContentType = jsonType;
            }
            return JsonResult;
        }

        public static JsonResult error(object content = null, resultActionEnum action = resultActionEnum.none, string jsonType = "applaction/json")
        {
            if (content == null) content = "失败";
            data["result"] = resultTypeEnum.ERROR.ToString();
            data["content"] = content;
            data["action"] = action.ToString();
            JsonResult.Data = data;
            if (jsonType != null)
            {
                JsonResult.ContentType = jsonType;
            }
            return JsonResult;
        }

    }
}
